﻿namespace Nomo.UnityCoreModule
{
    /// <summary>
    /// 为 <see cref="CoreModule.Direction"/> 枚举的成员提供扩展方法。
    /// </summary>
    public static class DirectionExtension
    {
        /// <summary>
        /// 获取表示方向的二维向量。
        /// </summary>
        /// <param name="direction">方向。</param>
        /// <returns></returns>
        public static UnityEngine.Vector2 ToVector2(this CoreModule.Direction direction)
        {
            var result = UnityEngine.Vector2.zero;
            if ((direction & CoreModule.Direction.Up) == CoreModule.Direction.Up)
            {
                result += UnityEngine.Vector2.up;
            }
            if ((direction & CoreModule.Direction.Left) == CoreModule.Direction.Left)
            {
                result += UnityEngine.Vector2.left;
            }
            if ((direction & CoreModule.Direction.Down) == CoreModule.Direction.Down)
            {
                result += UnityEngine.Vector2.down;
            }
            if ((direction & CoreModule.Direction.Right) == CoreModule.Direction.Right)
            {
                result += UnityEngine.Vector2.right;
            }
            return result;
        }
    }
}
